Skip to content

fix: Windows compatibility and correct hook configuration syntax#11

Merged
itz4blitz merged 2 commits intoitz4blitz:mainfrom
unRekable:fix/windows-compatibility-hooks
Feb 17, 2026
Merged

fix: Windows compatibility and correct hook configuration syntax#11
itz4blitz merged 2 commits intoitz4blitz:mainfrom
unRekable:fix/windows-compatibility-hooks

Conversation

@unRekable
Copy link
Contributor

Summary

This PR fixes hook errors on Windows and ensures consistent cross-platform behavior.

Changes

1. bin/hooks/session-start.js - Cross-platform CLI detection

Problem: The original code only checked one npm global path, which doesn't work on Windows.

Solution:

  • Check AGENTFUL_PARALLEL env var first (user override)
  • Try multiple npm global paths for Windows, macOS (Homebrew), and Linux
  • Default to enabled: true if CLI not found (newer Claude Code versions have parallel execution by default)
const possiblePaths = [
  // Windows npm global
  path.join(execSync('npm root -g', { encoding: 'utf8' }).trim(), '@anthropic-ai', 'claude-code', 'cli.js'),
  // Unix npm global
  '/usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js',
  // Homebrew on macOS
  '/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js',
];

2. bin/hooks/architect-drift-detector.js - Exit code handling

Problem: The hook exited with code 1 when drift was detected, which Claude Code interprets as a hook error.

Solution: Always exit with code 0. Drift detection is informational, not an error.

// Before
process.exit(driftDetected ? 1 : 0);

// After
process.exit(0);  // Always 0 - drift is informational, not an error

3. template/.claude/settings.json - Correct matcher syntax

Problem: PreToolUse hooks used "tools": ["Write", "Edit"] which is incorrect syntax and causes errors for tools not in the list (Glob, Read, etc.).

Solution: Use the documented matcher syntax with regex patterns:

// Before
"PreToolUse": [
  {
    "tools": ["Write", "Edit"],
    "hooks": [...]
  }
]

// After
"PreToolUse": [
  {
    "matcher": "Write|Edit|NotebookEdit",
    "hooks": [...]
  }
]

Testing

All hooks tested on Windows 11:

✅ session-start.js - Exit 0 (shows "parallel execution: ON")
✅ architect-drift-detector.js - Exit 0 (drift is informational)
✅ All other hooks - Exit 0

No more PostToolUse:Glob or PostToolUse:Read errors.

Related Issues

Fixes hook errors reported by Windows users when using Glob/Read tools.

unRekable and others added 2 commits February 17, 2026 13:22
- session-start.js: Add cross-platform CLI detection (Windows/macOS/Linux)
  - Check AGENTFUL_PARALLEL env var first
  - Try multiple npm global paths for Windows and Unix
  - Default to enabled if CLI not found (newer versions have it by default)

- architect-drift-detector.js: Fix exit code handling
  - Always exit 0 (drift is informational, not an error)
  - Non-zero exit codes are interpreted as hook errors by Claude Code

- settings.json template: Use correct matcher syntax
  - Replace "tools": ["Write", "Edit"] with "matcher": "Write|Edit|NotebookEdit"
  - The tools array syntax causes errors for non-listed tools (Glob, Read, etc.)
  - matcher uses regex patterns per Claude Code documentation

Fixes hook errors on Windows and ensures consistent behavior across platforms.
- Wrap `npm root -g` in its own try/catch so it doesn't blow up array
  construction on Windows when npm isn't in PATH
- Remove overly broad `Task\(` regex that matches any JS file
- Restore `enabled: false` for gate-exists and error paths so the
  detection function actually distinguishes enabled vs disabled
@itz4blitz itz4blitz merged commit 9b4c42a into itz4blitz:main Feb 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants